package com.matrix.admin.open.test.service.impl;

import com.matrix.admin.open.test.service.IJsonTestService;
import com.matrix.common.dto.poi.test.UserPoiTest;
import com.matrix.common.enums.SysDefault;
import com.matrix.common.utils.JSONUtils;
import com.matrix.common.vo.basic.response.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author liuweizhong
 * @since 2025-09-12 00:11
 */
@Slf4j
@Service
public class JsonTestServiceImpl implements IJsonTestService {
    @Override
    public BaseResponse<String> testJson() {
        String jsonStr = "{\"name\":\"liuweizhong\",\"id\":25}";
        UserPoiTest userPoiTest = JSONUtils.parseObject(jsonStr, UserPoiTest.class);

        Map<String, Object> stringObjectMap = JSONUtils.parseMap(jsonStr);

        String json = "[{\"name\":\"swx\",\"id\":18}," +
                "{\"name\":\"博尔特\",\"id\":55}," +
                "{\"name\":\"迪迦\",\"id\":1500}]";
        List<UserPoiTest> userPoiTests = JSONUtils.parseArray(json, UserPoiTest.class);

        List<Map<String, Object>> maps = JSONUtils.parseArrayMap(json);

        UserPoiTest person = new UserPoiTest();
        person.setName("swx");
        person.setId(18);

        String obj2jsonStr = JSONUtils.toJSONString(person);
        return BaseResponse.success(SysDefault.SUCCESS.getValue());
    }
}
